<script setup>
import { ref, reactive } from 'vue'
import { ElMessage } from 'element-plus'
import { User, Lock } from '@element-plus/icons-vue'

const loginForm = reactive({
  username: '',
  password: '',
  role: '学生'
})

const rules = reactive({
  username: [
    { required: true, message: '请输入用户名', trigger: 'blur' },
  ],
  password: [
    { required: true, message: '请输入密码', trigger: 'blur' },
  ],
  role: [
    { required: true, message: '请选择登录身份', trigger: 'change' }
  ]
})

const roles = [
  { label: '管理员', value: '管理员' },
  { label: '教师', value: '教师' },
  { label: '学生', value: '学生' }
]

const loginFormRef = ref(null)

const handleLogin = async (formEl) => {
  if (!formEl) return
  await formEl.validate((valid) => {
    if (valid) {
      ElMessage.success('登录成功')
      console.log('submit success')
    } else {
      console.log('error submit!')
      return false
    }
  })
}
</script>

<template>
  <div class="login-container">
    <el-card class="login-card">
      <div class="login-header">
        <h1>教务管理系统</h1>
        <h2>用户登录</h2>
      </div>
      <el-form
        ref="loginFormRef"
        :model="loginForm"
        :rules="rules"
        label-position="left"
        label-width="80px"
      >
        <el-form-item label="用户名" prop="username">
          <el-input
            v-model="loginForm.username"
            placeholder="请输入用户名"
          :prefix-icon="User"
          />
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input
            v-model="loginForm.password"
            type="password"
            placeholder="请输入密码"
          :prefix-icon="Lock"
            show-password
          />
        </el-form-item>
        <el-form-item label="登录身份" prop="role">
          <el-radio-group v-model="loginForm.role">
            <el-radio-button 
              v-for="role in roles"
              :key="role.value"
              :label="role.value"
            >
              {{ role.label }}
            </el-radio-button>
          </el-radio-group>
        </el-form-item>

        <el-form-item>
          <el-button
            type="primary"
            @click="handleLogin(loginFormRef)"
            style="width: 100%"
            size="large"
          >
            登录
          </el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<style scoped>
.login-container {
  display: flex;
  justify-content: center;
  align-items: center;
  min-width: 100%;
  min-height: 100vh;
  background: 
    linear-gradient(135deg, #3498db 0%, #2980b9 100%),
    repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.05) 0px, rgba(255, 255, 255, 0.05) 2px, transparent 2px, transparent 8px);
  background-attachment: fixed;
  background-size: cover;
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 0;
}

.login-container::before,
.login-container::after {
  content: '';
  position: absolute;
  width: 200vw;
  height: 200vh;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle, rgba(255, 255, 255, 0.1) 0%, transparent 60%);
  border-radius: 50%;
}

.login-container::before {
  animation: pulse 15s ease-in-out infinite;
}

.login-container::after {
  animation: pulse 15s ease-in-out infinite reverse;
}

@keyframes pulse {
  0% {
    transform: translate(-50%, -50%) scale(0.8);
    opacity: 0.5;
  }
  50% {
    transform: translate(-50%, -50%) scale(1.2);
    opacity: 0.8;
  }
  100% {
    transform: translate(-50%, -50%) scale(0.8);
    opacity: 0.5;
  }
}

.login-card {
  width: 460px;
  padding: 30px;
  border-radius: 15px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
  backdrop-filter: blur(8px);
  background: rgba(255, 255, 255, 0.98);
  position: relative;
  z-index: 1;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.login-header {
  text-align: center;
  margin-bottom: 40px;
}

.login-header h1 {
  color: #1a365d;
  font-size: 28px;
  margin-bottom: 10px;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.1);
}

.login-header h2 {
  color: #666;
  font-size: 20px;
  font-weight: normal;
}

:deep(.el-input__wrapper) {
  padding: 8px 15px;
}

:deep(.el-form-item) {
  margin-bottom: 25px;
}

:deep(.el-form-item__label) {
  text-align: left;
  font-weight: 500;
  white-space: nowrap;
  line-height: 32px;
}

:deep(.el-radio-button__inner) {
  padding: 8px 20px;
}

:deep(.el-button--primary) {
  padding: 12px 0;
  font-size: 16px;
}
</style>
